﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CrankShaftAnalysisSystem.SubForm
{
    public partial class FormResult : Form
    {
        public int[] IsValueOk { get; private set; } // 测量值是否符合要求
        public Dictionary<int, SolidBrush> ValueBrushDict = new Dictionary<int, SolidBrush>
        {
            { 2, new SolidBrush(Color.Black) },
            { 1, new SolidBrush(Color.Orange) },
            { 0, new SolidBrush(Color.Red) }
        };
        public FormResult()
        {
            InitializeComponent();
            listContent.DrawItem += ListContent_DrawItem;
            listContent.DrawMode = DrawMode.OwnerDrawFixed;
        }

        private void ListContent_DrawItem(object sender, DrawItemEventArgs e)
        {
            if (IsValueOk is null)
                return;
            var content = listContent.Items[e.Index].ToString();
            var brush = ValueBrushDict[IsValueOk[e.Index]];
            e.Graphics.DrawString(content, e.Font, brush, e.Bounds);
        }

        private void FormResult_FormClosing(object sender, FormClosingEventArgs e)
        {
            Hide();
            e.Cancel = true;
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            Hide();
        }

        public void RefreshList(string[] title, string[] value, int[] is_value_ok)
        {
            if (IsValueOk is null) IsValueOk = new int[is_value_ok.Length];
            Array.Copy(is_value_ok, IsValueOk, is_value_ok.Length);
            listContent.Items.Clear();
            listTitle.Items.Clear();
            listTitle.Items.AddRange(title);
            listContent.Items.AddRange(value);
        }
    }
}
